package com.dlc.beijingrfid.net.protocol;

import android.support.annotation.Nullable;
import com.dlc.beijingrfid.net.bean.BackBean;
import com.dlc.beijingrfid.net.bean.BucaoCategoryBean;
import com.dlc.beijingrfid.net.bean.DistributeOrderBean;
import com.dlc.beijingrfid.net.bean.DistributeOrderDetailBean;
import com.dlc.beijingrfid.net.bean.OrderBean;
import com.dlc.beijingrfid.net.bean.OrderDetailBean;
import com.dlc.beijingrfid.net.bean.ProductListBean;
import com.dlc.beijingrfid.net.bean.RFIDListBean;
import com.dlc.beijingrfid.net.bean.RFIDSpecListBean;
import com.dlc.beijingrfid.net.bean.WashRecordBean;
import com.dlc.beijingrfid.net.protocol.base.HttpProtocol;
import com.lzy.okgo.model.HttpParams;
import rx.Observable;

/**
 * 库存相关的协议
 */
public class StockProto extends HttpProtocol {

    private StockProto() {
    }

    private static class InstanceHolder {
        private static final StockProto sProtocol = new StockProto();
    }

    public static StockProto get() {
        return InstanceHolder.sProtocol;
    }


    /**
     * 获取布草分类
     *
     * @param error
     * @return
     */
    public Observable<BucaoCategoryBean> categorys(@Nullable String error) {
        return rxPost("categorys", null, BucaoCategoryBean.class, false, error);
    }

    /**
     * RFID分类
     *
     * @param rfid
     * @return
     */
    public Observable<RFIDSpecListBean> rfid_spec(String rfid) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("rfids", rfid);
        return  rxPost("rfid_spec", httpParams, RFIDSpecListBean.class, true, null);
    }
    /**
     * 订单列表
     *
     * @param apiName
     * @param callback
     */
    public void getOrder(String apiName, String page,String pagesize,Callback<OrderBean> callback) {
        HttpParams params = new HttpParams();
        params.put("page", page);
        params.put("pagesize", pagesize);
        post(apiName, params, OrderBean.class, true, callback);
    }
    public void getDistributeOrder(String apiName, Callback<DistributeOrderBean> callback) {
        post(apiName, null, DistributeOrderBean.class, true, callback);
    }
    public void getDistributeDetailOrder(String id, Callback<DistributeOrderDetailBean> callback) {
        HttpParams params = new HttpParams();
        params.put("id", id);
        post("distribute_detail", params, DistributeOrderDetailBean.class, true, callback);
    }
    /**
     * 订单列表详情
     *
     * @param id
     * @param callback
     */
    public void getOrderDetail(String apiName, String id, Callback<OrderDetailBean> callback) {
        HttpParams params = new HttpParams();
        params.put("id", id);
        post(apiName, params, OrderDetailBean.class, true, callback);

    }

    /**
     * 新增返洗订单
     *
     * @param
     * @return
     */
    public Observable<BackBean> order_back_new(String rfids) {
        HttpParams httpParams = new HttpParams();
        //httpParams.put("id", id);

        httpParams.put("rfids", rfids);

        return rxPost("order_back_new", httpParams, BackBean.class, true, null);
    }


    /**
     * 获取分类下的产品列表
     *
     * @param error
     * @return
     */
    public Observable<ProductListBean> goods(int category, @Nullable String error) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("category_id", category);
        return rxPost("goods", httpParams, ProductListBean.class, true, error);
    }

    /**
     * 获取RFID列表
     *
     * @param category
     * @param error
     * @return
     */
    public Observable<RFIDListBean> rfid(int category, int spec, int page, @Nullable String error) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("category_id", category);
        httpParams.put("spec_id", spec);
        //httpParams.put("goods_id", category);
        //httpParams.put("id", rfid); //  	RFID存储ID
        //httpParams.put("warehouse_id", category);
        //httpParams.put("ware_frame_id", category);
        //httpParams.put("cardno", category);
        if (page != 0) {
            httpParams.put("page", page);
        }
        //httpParams.put("pagesize", category);

        return rxPost("rfid", httpParams, RFIDListBean.class, true, error);
    }

    /**
     * 获取洗涤记录
     *
     * @param rfid
     * @param page
     * @param error
     * @return
     */
    public Observable<WashRecordBean> wash_record(String rfid, int page, @Nullable String error) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("cardno", rfid);
        if (page != 0) {
            httpParams.put("page", page);
        }
        return rxPost("wash_record", httpParams, WashRecordBean.class, true, error);
    }

    /**
     * 移库
     *
     * @param warehouseId
     * @param wareFrameId
     * @param rfids
     * @return
     */
    public Observable<WashRecordBean> warehouseMove(String warehouseId, String wareFrameId, String rfids) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("warehouse_id", warehouseId);
        httpParams.put("ware_frame_id", wareFrameId);
        httpParams.put("ids", rfids);
        return rxPost("warehouse_move", httpParams, WashRecordBean.class, true, null);
    }

    public void getBackOrderDetail(String apiName, String orderno, Callback<OrderDetailBean> callback) {
        HttpParams params = new HttpParams();
        params.put("orderno", orderno);
        post(apiName, params, OrderDetailBean.class, true, callback);

    }
}
